<!DOCTYPE HTML>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <title>设置</title>
        {$QPath}
        <link rel="stylesheet" type="text/css" href="__TMPL__../Admin/Public/base.css"/>
        <script type="text/javascript" src="__TMPL__../Admin/Public/mootools.js"></script>
        <script type="text/javascript" src="__TMPL__../Admin/Public/base.js"></script>
    </head>
    <body>
        <div id="container">
            <table class="tabmenu" cellspacing="0">
                <tbody>
                    <tr>
                        <td class="wedge">&nbsp;</td>
                        <td id="tdmyinfo" class="wmenu here"><a href="javascript:tab('myinfo')"><span>我的信息</span></a></td>
                        <td id="tdeditpwd" class="wmenu"><a href="javascript:tab('editpwd')"><span>修改密码</span></a></td>
                        <td>&nbsp;</td>
                    </tr>
                </tbody>
            </table>
            <div class="main">
                <ul class="fnc">
                    <li><button type="button" class="btn primary" onclick="doAction('save')">保存</button></li>
                </ul>
                <input id="edittype" type="hidden" value="myinfo">
                <form id="myinfoForm" method="post" action="__URL__/saveSetting">
                    <input type="hidden" name="editype" value="myinfo"/>
                    <table class="ips" id="myinfo">
                        <tbody>
                            <tr>
                                <th><label for="pk2">用户名</label></th>
                                <td>
                                    <label>{$userVo['account']}</label>
                                </td>
                            </tr>
                            <tr>
                                <th class="essential"><label for="pk4">真实姓名</label></th>
                                <td>
                                    <input type="text" id="pk4" name="realname" size="40" maxlength="32" value="{$userVo['realname']}"/>
                                    <p class="hint">长度不能超过32个字符</p>
                                </td>
                            </tr>
                            <tr>
                                <th><label for="pk5">邮箱</label></th>
                                <td>
                                    <input type="text" id="pk5" name="email" size="60" maxlength="64" value="{$userVo['email']}"/>
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </form>
                <form id="editpwdForm" method="post" action="__URL__/saveSetting">
                    <input type="hidden" name="editype" value="pwd"/>
                    <table class="ips" id="editpwd" style="display:none">
                        <tbody>
                            <tr>
                                <th class="essential"><label for="oldpassword">输入原密码</label></th>
                                <td><input type="password" id="oldpassword" name="oldpassword" maxlength="32"/></td>
                            </tr>
                            <tr>
                                <th class="essential"><label for="newpass">输入新密码</label></th>
                                <td><input type="password" id="newpass" name="password" class="textInput" /><p class="hint">长度至少六个字符</p></td>
                            </tr>
                            <tr>
                                <th class="essential"><label for="renewpass">再输入新密码</label></th>
                                <td><input type="password" id="renewpass" class="textInput" /></td>
                            </tr>
                        </tbody>
                    </table>
                </form>
                <script type="text/javascript">
                    function tab(etype){
                        var editType=$("edittype"),oldType=editType.getProperty("value");
                        if(oldType!==etype){
                            //table change
                            $(oldType).setStyle("display","none");
                            $(etype).setStyle("display","block");
                            //a link class change
                            $("td"+oldType).removeClass("here");
                            $("td"+etype).addClass("here");
                            editType.setProperty("value",etype);
                        }
                    }
                </script>
                <ul class="fnc">
                    <li><button type="button" class="btn primary" onclick="doAction('save')">保存</button></li>
                </ul>
            </div>
        </div>
        <script type="text/javascript">
            var mif,epf;
            function doAction(actionType){
                var editType=$("edittype").getProperty("value");
                if("myinfo"==editType){
                    var pk4=$("pk4");   // 真实姓名
                    if(pk4.getProperty("value").trim()==""){
                        mif.showTip(pk4,"真实姓名不能为空,请填写");
                        return;
                    }else{
                        mif.hideTip(pk4);
                    }
                }else if("editpwd"==editType){
                    var oldObj=$("oldpassword");
                    var oldpass=oldObj.getProperty("value").trim();
                    if(""==oldpass){
                        epf.showTip(oldObj,"请输入原密码");
                        return;
                    }else{
                        epf.hideTip(oldObj);
                    }
                    var newObj=$("newpass");
                    var newpass=newObj.getProperty("value").trim();
                    if(newpass.length<6){
                        epf.showTip(newObj,"新密码的长度少于六位，请重新输入");
                        return;
                    }else{
                        epf.hideTip(newObj);
                    }
                    var renewObj=$("renewpass");
                    var repass=renewObj.getProperty("value").trim();
                    if(repass!=newpass){
                        epf.showTip(renewObj,"两次输入新密码不一致，请重新输入");
                        return;
                    }else{
                        epf.hideTip(renewObj);
                    }
                }
                //ajax提交保存
                var fm=$(editType+"Form");
                fm.set('send',{
                    url:'__URL__/saveSetting',
                    method:'post',
                    onRequest:function(){
                        top.showMsg("正在保存",{type:"running"});
                    },
                    onSuccess:function(txt){
                        var json=JSON.decode(txt);
                        if(json.result=="success"){
                            top.showMsg("保存成功",{type:"success",disappear:4});
                        }else{
                            top.showMsg("保存失败:"+json.msg,{type:"failure",disappear:4});
                        }
                    },
                    onFailure:function(){
                        top.showMsg("保存失败",{type:"failure",disappear:4});
                    }
                });
                fm.send();
            }
            $(window).addEvent('domready',function(){
                mif=new yaForm($("myinfoForm"));
                epf=new yaForm($("editpwdForm"));
            });
        </script>
    </body>
</html>
